<?php 
namespace Teacher\Controller;

use Admin\Controller\AdminbaseController;
class ContentadminController extends AdminbaseController{
	
	protected $m;
	protected $imgLogic;
	protected $fileLogic;
	protected $standard;
	protected $Contentsstandard;
	protected $ret;//getsulie函数的全局赋值
	protected $ContentsLogic;
	
	function _initialize() {
		parent::_initialize();
		$this->m = D('YgclTeacherContents');
		$this->imgLogic = D('MaterialImages','Logic');
		$this->fileLogic = D('MaterialFiles','Logic');
		$this->standard = D('Standard');
		$this->ContentsLogic = D('Contents','Logic');
		$this->Contentsstandard = D('ContentsStandard');
	}
	
	
	/**
	 * @name 资讯列表
	 * @auth adminleft
	 */
	public function index(){
		if(!$_GET['status']){
			$_GET['status'] = 0;
		}
		$this->uid = $this->curUser['uid'];
		$this->display();
	}
	
	
	public function edit(){
		if(isset($_GET['id'])){
			$info = $this->m->relation(true)->find($_GET['id']);		
			$this->info = $info;
		}
		$this->uid = $this->curUser['uid'];
		$this->display();
	}
	
	public function edit_post(){
		if(IS_POST){
			$_POST['update_time'] = Date('Y-m-d H:i:s');
			if($_POST['id']){
				if($this->m->create()){
					$id = $_POST['id'];
					if($this->m->save()){
						$this->imgLogic->save($id,'content',$_POST);
						$this->fileLogic->save($id,'content',$_POST);
						$this->success('更新成功');
					}else{
						$this->error('更新失败');
					}
				}
			}else{
				$_POST['create_time'] = Date('Y-m-d H:i:s');
				if($this->m->create()){
					$id = $this->m->add();
					if($id){
						$this->imgLogic->save($id,'content',$_POST);
						$this->fileLogic->save($id,'content',$_POST);
						$this->success('添加成功');
					}else{
						$this->error('添加失败');
					}
				}
			}
		}
	}
	
	public function del(){
		$id = array_unique((array)I('ids',0));
		if ( empty($id) ) {
			$this->error('请选择要操作的数据!');
		}
		$map = array('id' => array('in', $id));
		$info = $this->m->where($map)->find();
		if($this->m->where($map)->delete()){
			//删除文章下面的图片
			foreach($id as $i){
				$this->imgLogic->del($i,'content');
				$this->fileLogic->del($i,'content');
			}
			$this->success('删除成功');
		} else {
			$this->error('删除失败！');
		}
	}
	
	public function listorders() {
		$status = parent::_listorders($this->m);
		if ($status) {
			$this->success("排序更新成功！",U('index'));
		} else {
			$this->error("排序更新失败！");
		}
	}
	
	public function changestatus(){
		$data[$this->m->getPk()] = $_REQUEST['id'];
		$data['status'] = $_REQUEST['status'];
		$data['update_time'] = date('Y-m-d H:i:s');
		if($this->m->save($data)){
			$this->success('状态更新成功');
		}else{
			$this->error('状态更新失败');
		}
	}
}

?>